package com.hzqy.persistence.dao.hqjc;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Repository
public class HqjcDao extends PersistenceDao<PmsUserVo, Integer>{
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	public CmCatalogVo selectCatalog(int f_catalog_id){
		return getSqlSession().selectOne(this.getNamespace() + "selectCatalog", f_catalog_id);
	}
	
	public List<CmContentVo> selectSeriesListByCatalogId(int id,int pageNo,int pageSize){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectSeriesListByCatalogId", map);
	}
	
	public int selectCatalogInfoListByParentCatalogIdCount(int f_catalog_id,int f_po_id) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_po_id", f_po_id);
		return getSqlSession().selectOne(this.getNamespace() + "selectCatalogInfoListByParentCatalogIdCount", map);
	}
	public List<CmCatalogVo> selectCatalogInfoListByParentCatalogId(int f_catalog_id,int f_po_id,int pageNo,int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", f_catalog_id);
		map.put("f_po_id", f_po_id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectCatalogInfoListByParentCatalogId", map);
	}
	public int selectContentCount(int id,int f_po_id,String f_cp_cprid,CmContentVo contentVo){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("f_cp_cprid", f_cp_cprid);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_catalog_parentid", contentVo.getF_catalog_parentid());
		map.put("f_cc_interfaceType", contentVo.getF_cc_interfaceType());
		map.put("f_cc_director", contentVo.getF_cc_director());
		map.put("f_cc_category", contentVo.getF_cc_category());
		return getSqlSession().selectOne(this.getNamespace() + "selectContentCount", map);
	}
	public int selectContentCountIn(String id,int f_po_id,String f_cp_cprid,CmContentVo contentVo){
		Map<String,Object> map = new HashMap<String, Object>();
//		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("f_cp_cprid", f_cp_cprid);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_catalog_parentid", contentVo.getF_catalog_parentid());
		map.put("f_cc_interfaceType", contentVo.getF_cc_interfaceType());
		map.put("f_cc_category", contentVo.getF_cc_category());
		if(id.indexOf(",")!=-1) {
			/* map.put("f_catalog_id", id.split(",")); */
			map.put("f_catalog_id", id);
			return getSqlSession().selectOne(this.getNamespace() + "selectContentCountIn", map);
		}else if(id!=null&&id.matches("\\d+")){
			map.put("f_catalog_id", Integer.parseInt(id));
			return getSqlSession().selectOne(this.getNamespace() + "selectContentCount", map);
		}
		return 0;
	}
	
	public List<CmContentVo> selectContentListByCatalogId(int id,String f_po_id,int pageNo,int pageSize,String f_cp_cprid,CmContentVo contentVo){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		map.put("f_cp_cprid", f_cp_cprid);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_catalog_parentid", contentVo.getF_catalog_parentid());
		map.put("f_catalog_desc", contentVo.getF_catalog_desc());
		map.put("f_cc_interfaceType", contentVo.getF_cc_interfaceType());
		map.put("f_cc_actorslist", contentVo.getF_cc_actorslist());
		map.put("f_cc_type", contentVo.getF_cc_type());
		map.put("f_cc_director", contentVo.getF_cc_director());
		map.put("f_cc_category", contentVo.getF_cc_category());
		String sort_column=contentVo.getSort_column();
		if("".equals(sort_column)||sort_column==null||"undefined".equals(sort_column)){
			contentVo.setSort_column("f_ccc_viewindex desc, f_cc_id desc");
		}
		map.put("sort_column", contentVo.getSort_column());
		return getSqlSession().selectList(this.getNamespace() + "selectContentListByCatalogId", map);
	}
	public List<CmContentVo> selectContentListByCatalogIdIn(String id,int f_po_id,int pageNo,int pageSize,String f_cp_cprid,CmContentVo contentVo){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_cco_orgId", f_po_id);
		map.put("firstResult", pageNo);
//		map.put("f_catalog_id", id);
		map.put("pageSize", pageSize);
		map.put("f_cp_cprid", f_cp_cprid);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_catalog_parentid", contentVo.getF_catalog_parentid());
		map.put("f_catalog_desc", contentVo.getF_catalog_desc());
		map.put("f_cc_interfaceType", contentVo.getF_cc_interfaceType());
		map.put("f_cc_category", contentVo.getF_cc_category());
		String sort_column=contentVo.getSort_column();
		if("".equals(sort_column)||sort_column==null||"undefined".equals(sort_column)){
			contentVo.setSort_column("f_ccc_viewindex desc, f_cc_id desc");
		}
		map.put("sort_column", contentVo.getSort_column());
		if(id.indexOf(",")!=-1) {
			/* map.put("f_catalog_id", id.split(",")); */
			map.put("f_catalog_id", id);
			return getSqlSession().selectList(this.getNamespace() + "selectContentListByCatalogIdIn", map);
		}else if(id!=null&&id.matches("\\d+")){
			map.put("f_catalog_id", Integer.parseInt(id));
			return getSqlSession().selectList(this.getNamespace() + "selectContentListByCatalogId", map);
		}
		return new ArrayList<CmContentVo>();
	}
	public List<CmContentVo> selectContentListByCatalogIds(int id,int f_po_id,CmContentVo contentVo){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("f_cp_cprid", contentVo.getF_cc_cprid());
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		map.put("f_cc_actors", contentVo.getF_cc_actors());
		map.put("f_catalog_parentid", contentVo.getF_catalog_parentid());
		map.put("f_catalog_desc", contentVo.getF_catalog_desc());
		map.put("f_ccc_sdStatus",contentVo.getF_ccc_sdStatus());
		String sort_column=contentVo.getSort_column();
		if("".equals(sort_column)||sort_column==null||"undefined".equals(sort_column)){
			contentVo.setSort_column("f_ccc_viewindex desc, f_cc_id desc");
		}
		map.put("sort_column", contentVo.getSort_column());
		return getSqlSession().selectList(this.getNamespace() + "selectContentListByCatalogIds", map);
	}
	
	public List<CmCatalogVo> selectCatalogListByCatalogParentId(int id){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_parentid", id);
		return getSqlSession().selectList(this.getNamespace() + "selectCatalogListByCatalogParentId", map);
	}
	
	public CmContentVo selectContent(CmContentVo contentVo){
		return getSqlSession().selectOne(this.getNamespace() + "selectContent", contentVo);
	}
	
	public int selectSeriesCount(CmContentVo contentVo){
		return getSqlSession().selectOne(this.getNamespace() + "selectSeriesCount", contentVo);
	}
	
	public List<CmSeriesVo> selectAllSeries(CmContentVo contentVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectAllSeries",contentVo);
	}
	
	public List<CmSeriesVo> selectSeriesList(int id,int pageNo,int pageSize){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_cc_id", id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		return getSqlSession().selectList(this.getNamespace() + "selectSeriesList", map);
	}
	
	public CmSeriesVo selectSeries(int f_ssc_id){
		return getSqlSession().selectOne(this.getNamespace() + "selectSeries", f_ssc_id);
	}
	
	public int selectContentIDByCode(String f_cc_code) {
		return getSqlSession().selectOne(this.getNamespace() + "selectContentIDByCode", f_cc_code);
	}
	
	public List<CmContentVo> selectContentListByCatalogIdRqph(int id,int f_po_id,int pageNo,int pageSize,String f_cp_cprid,CmContentVo contentVo){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_catalog_id", id);
		map.put("f_cco_orgId", f_po_id);
		map.put("firstResult", pageNo);
		map.put("pageSize", pageSize);
		map.put("f_cp_cprid", f_cp_cprid);
		map.put("f_cc_searchname", contentVo.getF_cc_searchname());
		map.put("f_cc_name", contentVo.getF_cc_name());
		map.put("f_sa_id", contentVo.getF_sa_id());
		return getSqlSession().selectList(this.getNamespace() + "selectContentListByCatalogIdRqph", map);
	}
	
	public int selectGlobalContentListByCastSearchNameCount(CmContentVo contentVo) {
		return getSqlSession().selectOne(this.getNamespace()+"selectGlobalContentListByCastSearchNameCount",contentVo);
	}
	
	public List<CmContentVo> selectGlobalContentListByCastSearchName(CmContentVo contentVo) {
		return getSqlSession().selectList(this.getNamespace()+"selectGlobalContentListByCastSearchName",contentVo);
	}
	
	public List<CmContentVo> selectGlobalContentListByActorSearchName(CmContentVo contentVo) {
		return getSqlSession().selectList(this.getNamespace()+"selectGlobalContentListByActorSearchName",contentVo);
	}
	
	public int selectGlobalContentListCount(CmContentVo contentVo) {
		return getSqlSession().selectOne(this.getNamespace()+"selectGlobalContentListCount",contentVo);
	}
	
	public List<CmContentVo> selectGlobalContentList(CmContentVo contentVo) {
		return getSqlSession().selectList(this.getNamespace()+"selectGlobalContentList",contentVo);
	}

	public List<CmCatalogVo> selectCatalogListByContent(CmContentVo contentVo) {
		return getSqlSession().selectList(this.getNamespace()+"selectCatalogListByContent",contentVo);
	}
	
	public List<CmContentVo> selectGlobalContentListByTags(CmContentVo contentVo) {
		return getSqlSession().selectList(this.getNamespace()+"selectGlobalContentListByTags",contentVo);
	}

	public PmsOrgVo selectPmsOrgByContentName(String serverId) {
		return getSqlSession().selectOne(this.getNamespace()+"selectPmsOrgByContentName",serverId);
	}

	public CmCatalogVo selectParentCatalogById(int f_cc_id) {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("f_cc_id", f_cc_id);
		return getSqlSession().selectOne(this.getNamespace()+"selectParentCatalogById",map);
	}
	
	public String selectIdsByOrgParentId(PmsOrgVo pmsOrgVo){
		return getSqlSession().selectOne(this.getNamespace() + "selectIdsByOrgParentId", pmsOrgVo);
	}
}
